package SentenceTranslator;

import Include.ASMConstructor;
import Common.REG;
import Include.Symbol;
import Include.TACLine;
import Main.SymbolManager;

import java.util.ArrayList;
import java.util.List;


public class CallTranslator {
    public List<String> SentenceTranslate(SymbolManager SymbolManager, TACLine tacLine) {
        List<String> asmLines = new ArrayList<>();
        String fun_name = tacLine.src1.value;
        List<String> ASMLines = new ArrayList<String>();
        ASMLines.add(ASMConstructor.construct_asm("call", fun_name));

        Symbol fun = SymbolManager.resolveFun(fun_name);
        // print("cnm")
        // print(fun.fun_para_type_list)
        if (fun != null) {
            int para_num = (fun.fun_para_type_list == null) ? 0 : fun.fun_para_type_list.size();
            SymbolManager.setEspBias(-4 * para_num);
            ASMLines.add(ASMConstructor.construct_asm("add", REG.ESP, String.valueOf(4 * para_num)));
        }
        return ASMLines;
    }


}
